﻿<?php
	header("Content-Type:text/html;charset=UTF-8");
	require_once 'config.php';
?>
<html>
<head>
<title>得到单个商品信息</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script src=js/colors.js></script>
</head>
<body>
<p>此DEMO的功能:得到单个商品信息</p>
<p id="msgs" style="height:24px;">
<?php
	$ref =$_SERVER['SCRIPT_NAME'];
	if(empty($sessions)){
		echo 'SESSION状态：异常<a href="'.$sessionurl.$appKey.'&ref='.$ref.'">获取Session</a>';exit;
	}else{
		echo 'SESSION状态：正常 <a href="login.php?ac=logout&ref='.$ref.'">退出登陆</a>';
	}
?>
</p>
<?php
	/* Build By fhalipay */

/* 得到单个商品信息 Start*/
	
	//参数数组
	$paramArr = array(

		/* API系统级输入参数 Start */

	    	'method' => 'taobao.item.get',  //API名称
//		   'session' => $sessions, //session
	     'timestamp' => date('Y-m-d H:i:s'),			
		    'format' => 'xml',  //返回格式,本demo仅支持xml
    	   'app_key' => $appKey,  //Appkey			
	    		 'v' => '2.0',   //API版本号		   
		'sign_method'=> 'md5', //签名方式			

		/* API系统级参数 End */				 

		/* API应用级输入参数 Start*/

	    	'fields' => 'iid,detail_url,num_iid,title,nick,type,cid,seller_cids,props,input_pids,input_str,desc,pic_url,num,valid_thru,list_time,delist_time,stuff_status,location,price,post_fee,express_fee,ems_fee,has_discount,freight_payer,has_invoice,has_warranty,has_showcase,modified,increment,auto_repost,approve_status,postage_id,product_id,auction_point,property_alias,item_imgs,prop_imgs,skus,outer_id,is_virtual,is_taobao,is_ex,videos,is_3D,score,volume,one_station',  //返回字段
//              'nick' => $userNick,  //卖家昵称
		   'num_iid' => $iid, //商品id  
//		   'num_iid' => $num_iid,//商品数字id  
			  
		/* API应用级输入参数 End*/
	);


	//生成签名
	$sign = createSign($paramArr,$appSecret);
	
	//组织参数
	$strParam = createStrParam($paramArr);
	$strParam .= 'sign='.$sign;
	
	//构造Url
	$urls = $url.$strParam;

	$result = vita_get_url_content($urls);

	//解析Xml数据
	$result = getXmlData($result);
	
	//获取返回信息
	$item = $result['item'];
	
/* 得到单个商品信息 End*/	


?>
<?php 
	if(empty($item)){
	//返回错误信息
		echo '不存在的商品';
	}else{
?>
<table border="0" width="950px" class="table">
  <tr>
    <td colspan="2" align="center"><b><?php echo $item['title']?> </b></td>
    <td align="right"><a href="edit.php?iid=<?php echo $iid?>">[编辑商品]</a></b></td>
  </tr>
  <tr>
    <td width="310"><?php print_r($item['item_imgs']);?></td>
    <td colspan="2">支持会员打折：<?php echo gethas_discount($item['has_discount'])?></td>
  </tr>
  <tr>
    <td width="310" height="310" rowspan="4"><img src="<?php echo $item['pic_url']?>_310x310.jpg" alt="" ></td>
    <td colspan="2"><?php echo getTypes($item['type'])?>：<?php echo $item['price']?>　元</td>
  </tr>
  <tr>
    <td colspan="2">运费：
      <?php    

	if (!empty($item['postage_id'])){
	//取得运费模板
	$paramArr = array(

		/* API系统级输入参数 Start */

		    'method' => 'taobao.postage.get',   //API名称
	     'timestamp' => date('Y-m-d H:i:s'),			
		    'format' => 'xml',  //返回格式,本demo仅支持xml
    	   'app_key' => $appKey,  //Appkey			
	    		 'v' => '2.0',   //API版本号		   
		'sign_method'=> 'md5', //签名方式			

		/* API系统级参数 End */			

		/* API应用级输入参数 Start*/

			'fields' => 'postage_id,name,memo,created,modified,post_price,post_increase,express_price,express_increase,ems_price,ems_increase,postage_mode_list,postage_mode.id,postage_mode.type,postage_mode.dests,postage_mode.price',
	    'postage_id' => $item['postage_id'],
		'nick'=> $item['nick'],
		/* API应用级输入参数 End*/	
	);

	//生成签名
	$sign = createSign($paramArr,$appSecret);
	
	//组织参数
	$strParam = createStrParam($paramArr);
	$strParam .= 'sign='.$sign;
	
	//构造Url
	$urls = $url.$strParam;

	//连接超时自动重试
	$cnt=0;	
	while($cnt < 3 && ($postages=@vita_get_url_content($urls))===FALSE) $cnt++;
	
	//解析Xml数据
	$postage = getXmlData($postages);

	//取得运费模板
	$express_fee = $postage['postage']['express_price'];
	$post_price = $postage['postage']['post_price'];
	$ems_fee = $postage['postage']['ems_price'];
	echo '平邮：'.$post_price.'元 EMS：'.$ems_fee.'元　快递：'.$express_fee.'元';
	}else{
	echo '平邮：'.$item['post_fee'].'元 EMS：'.$item['ems_fee'].'元　快递：'.$item['express_fee'];
	}
?></td>
  </tr>
  <tr>
    <td>有无发票：<?php echo gethas_invoice($item['has_invoice'])?></td>
    <td>有无保修：<?php echo gethas_warranty($item['has_warranty'])?></td>
  </tr>
  <tr>
    <td>所在地区：<?php echo $item['location']['state'].$item['location']['city']?></td>
    <td>宝贝类型：<?php echo getstuff_status($item['stuff_status'])?></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><?php

	if(!empty($item['input_pids'])){	
	$paramArr = array(

		/* API系统级输入参数 Start */

		    'method' => 'taobao.itemprops.get',   //API名称
	     'timestamp' => date('Y-m-d H:i:s'),			
		    'format' => 'xml',  //返回格式,本demo仅支持xml
    	   'app_key' => $appKey,  //Appkey			
	    		 'v' => '2.0',   //API版本号		   
		'sign_method'=> 'md5', //签名方式			

		/* API系统级参数 End */			

		/* API应用级输入参数 Start*/

			'fields' => 'name',
	      	   'cid' => $item['cid'], //Num_iid
		       'pid' => $item['input_pids'], //推广者昵称
	
		/* API应用级输入参数 End*/	
	);

	//生成签名
	$sign = createSign($paramArr,$appSecret);
	
	//组织参数
	$strParam = createStrParam($paramArr);
	$strParam .= 'sign='.$sign;
	
	//构造Url
	$urls = $url.$strParam;

	//连接超时自动重试
	$cnt=0;	
	while($cnt < 3 && ($prop_values=@vita_get_url_content($urls))===FALSE) $cnt++;
	
	//解析Xml数据
	$item_prop = getXmlData($prop_values);

	$item_prop = $item_prop['item_props']['item_prop'];
	

	if(empty($item_prop)){
		echo '';
	}else{	
	  
		if (count($item_prop['name'])<'1'){
			foreach ($item_prop as $prop => $key){
				echo '<font color=red>'.$key['prop_name'].'</font>：<font color=green>'.$key['name'].'</font><br />';
			}
		}else{
			echo '<font color=red>'.$item_prop['name'].'</font>：<font color=green>'.$item['input_str'].'</font>';
		}
	}
	}?>
    <td></td>
  </tr>
  <tr>
    <td align="left">&nbsp;</td>
    <td colspan="2" align="left"><?php

	if(!empty($item['props'])){	
	$paramArr = array(

		/* API系统级输入参数 Start */

		    'method' => 'taobao.itempropvalues.get',   //API名称
	     'timestamp' => date('Y-m-d H:i:s'),			
		    'format' => 'xml',  //返回格式,本demo仅支持xml
    	   'app_key' => $appKey,  //Appkey			
	    		 'v' => '2.0',   //API版本号		   
		'sign_method'=> 'md5', //签名方式			

		/* API系统级参数 End */			

		/* API应用级输入参数 Start*/

			'fields' => 'cid,pid,prop_name,vid,name,name_alias,status,sort_order',
	      	   'cid' => $item['cid'], //Num_iid
		       'pvs' => $item['props'], //推广者昵称
	
		/* API应用级输入参数 End*/	
	);

	//生成签名
	$sign = createSign($paramArr,$appSecret);
	
	//组织参数
	$strParam = createStrParam($paramArr);
	$strParam .= 'sign='.$sign;
	
	//构造Url
	$urls = $url.$strParam;

	//连接超时自动重试
	$cnt=0;	
	while($cnt < 3 && ($prop_values=@vita_get_url_content($urls))===FALSE) $cnt++;
	
	//解析Xml数据
	$prop_values = getXmlData($prop_values);

	$prop_value = $prop_values['prop_values']['prop_value'];
	

	if(empty($prop_values)){
		echo '';
	}else{	
	  
		if (count($prop_value['name'])<'1'){
			foreach ($prop_value as $prop => $key){
				echo '<font color=red>'.$key['prop_name'].'</font>：<font color=green>'.$key['name'].'</font><br />';
			}
		}else{
			echo '<font color=red>'.$prop_value['prop_name'].'</font>：<font color=green>'.$prop_value['name'].'</font>';
		}
	}
	}?></td>
  </tr>
  <tr>
    <td colspan="3"> 商品详情 
  </tr>
  <tr>
    <td colspan="3"><?php 
	//商品详情
	 echo $item['desc']
	?></td>
  </tr>
</table>
<?php
	}
?>
</body>
</html>
